
#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/module.h>
#include<linux/moduleparam.h>

int int_param, arr_param[4];
char *str_param;
int cb_param = 0;

module_param(int_param, int, S_IRUSR|S_IWUSR);
module_param(str_param, charp, S_IRUSR|S_IWUSR);
module_param_array(arr_param, int, NULL, S_IRUSR|S_IWUSR);

int notify_param(const char *val, const struct kernel_param *kp)
{
  int res = param_set_int(val, kp);
  if(res == 0) {
    pr_info("New value of cb_param = %d\n", cb_param);
    return 0;
  }
  return -1;
}
const struct kernel_param_ops my_param_ops =
{
  .set = &notify_param,
  .get = &param_get_int,
};
module_param_cb(cb_param, &my_param_ops, &cb_param, S_IRUGO|S_IWUSR );

static int __init hello_world_init(void)
{
  int i;
  pr_info("int_param = %d\ncb_param = %d\nstr_param = %s\n",
          int_param, cb_param, str_param);
  for (i = 0; i < ARRAY_SIZE(arr_param); i++)
    pr_info("arr_param[%d] = %d\n", i, arr_param[i]);
  pr_info("Kernel Module Inserted!\n");
  return 0;
}

static void __exit hello_world_exit(void)
{
    pr_info("Kernel Module Removed!\n");
}

// 模块入口和出口
module_init(hello_world_init);
module_exit(hello_world_exit);

// 模块参数
MODULE_LICENSE("GPL");
MODULE_AUTHOR("feifei <feifei@gmail.com>");
MODULE_DESCRIPTION("A simple linux device driver");
MODULE_VERSION("1.0");